from commons.entity.po.travel import Travel

from commons.entity.po.model import db


class Reimbursement(db.Model):
    __tablename__ = 'reimbursement'

    reimbursement_id = db.Column(
        db.Integer, primary_key=True, autoincrement=True, info='报销编号')
    food_cost = db.Column(db.Float, info='餐饮费')
    transport_cost = db.Column(db.Float, info='交通费')
    hotel_cost = db.Column(db.Float, info='住宿费')
    apply_date = db.Column(db.Date, info='申请时间')
    detail = db.Column(db.String(255), info='报销详情')
    travel_id = db.Column(db.ForeignKey(
        'travel.travel_id'), index=True, info='出差编号')

    travel = db.relationship('Travel', primaryjoin='Reimbursement.travel_id == Travel.travel_id',
                             backref='reimbursements')

    def to_dict(self):
        return {
            'reimbursement_id': self.reimbursement_id,
            'food_cost': self.food_cost,
            'transport_cost': self.transport_cost,
            'hotel_cost': self.hotel_cost,
            'apply_date': self.apply_date.isoformat() if self.apply_date else None,
            'detail': self.detail,
            'travel_id': self.travel_id
        }

    def to_dict_2(self):
        return {
            'reimbursementId': self.reimbursement_id,
            'foodCost': self.food_cost,
            'transportCost': self.transport_cost,
            'hotelCost': self.hotel_cost,
            'applyDate': self.apply_date.isoformat() if self.apply_date else None,
            'detail': self.detail,
            'travelId': self.travel_id
        }
